<template>
  <div class="root">
    <!-- 面包屑 -->
    <el-breadcrumb :separator-icon="ArrowRight">
      <el-breadcrumb-item :to="{ path: '/screen' }"
        >首页大屏</el-breadcrumb-item
      >
      <el-breadcrumb-item>仓库管理员</el-breadcrumb-item>
    </el-breadcrumb>

    <div class="content">
      <!-- 仓库管理员信息 -->
      <el-row>
        <!-- 左边 -->
        <el-col :span="8" style="padding-right: 10px">
          <el-card class="box-card">
            <div class="user">
              <img src="../../assets/img/daojiang.jpg" alt="" />
              <div class="userinfo">
                <p class="name">刀酱</p>
                <p class="access">仓库管理员</p>
              </div>
            </div>
            <div class="login-info">
              <p>上次登录时间:<span>2023-3-1</span></p>
              <p>上次登录地点:<span>青岛</span></p>
            </div>
          </el-card>
          <!-- 
            tableLabel 是一个数组
            val 代表数组中每一项，
            key 代表数组的索引
            可以在标签内使用数组的元素，如果数组中的每一项还有数组，则可以嵌套多层for循环
           -->
          <el-card style="margin-top: 20px; height: 452px">
            <el-table :data="tableData" style="width: 100%">
              <!-- <el-table prop="name" label="课程" />
              <el-table-column prop="todayBuy" label="今日购买" />
              <el-table-column prop="monthBuy" label="本月购买" />
              <el-table-column prop="totalBuy" label="总购买" /> -->
              <el-table-column
                v-for="(val, key) in tableLabel"
                :key="key"
                :prop="key"
                :label="val"
              ></el-table-column>
            </el-table>
          </el-card>
        </el-col>
        <!-- 右边 -->
        <el-col :span="16" style="padding-left: 10px">
          <div class="num">
            <el-card :body-style="{ display: 'flex', padding: '0' }">
              <i class="icon"
                ><el-icon><SuccessFilled /></el-icon
              ></i>
              <div class="detail">
                <p class="price">￥{{ countData[0].value }}</p>
                <p class="dec">{{ countData[0].name }}</p>
              </div>
            </el-card>
            <el-card :body-style="{ display: 'flex', padding: '0' }">
              <i class="icon"
                ><el-icon><SuccessFilled /></el-icon
              ></i>
              <div class="detail">
                <p class="price">￥{{ countData[1].value }}</p>
                <p class="dec">{{ countData[1].name }}</p>
              </div>
            </el-card>
            <el-card :body-style="{ display: 'flex', padding: '0' }">
              <i class="icon"
                ><el-icon><SuccessFilled /></el-icon
              ></i>
              <div class="detail">
                <p class="price">￥{{ countData[2].value }}</p>
                <p class="dec">{{ countData[2].name }}</p>
              </div>
            </el-card>
            <el-card :body-style="{ display: 'flex', padding: '0' }">
              <i class="icon"
                ><el-icon><SuccessFilled /></el-icon
              ></i>
              <div class="detail">
                <p class="price">￥{{ countData[3].value }}</p>
                <p class="dec">{{ countData[3].name }}</p>
              </div>
            </el-card>
            <el-card :body-style="{ display: 'flex', padding: '0' }">
              <i class="icon"
                ><el-icon><SuccessFilled /></el-icon
              ></i>
              <div class="detail">
                <p class="price">￥{{ countData[4].value }}</p>
                <p class="dec">{{ countData[4].name }}</p>
              </div>
            </el-card>
            <el-card :body-style="{ display: 'flex', padding: '0' }">
              <i class="icon"
                ><el-icon><SuccessFilled /></el-icon
              ></i>
              <div class="detail">
                <p class="price">￥{{ countData[5].value }}</p>
                <p class="dec">{{ countData[5].name }}</p>
              </div>
            </el-card>
          </div>
          <el-card style="height: 280px">
            <!-- 折线图 -->
            <div ref="echats1" style="height: 280px"></div>
          </el-card>
          <div class="graph" style="height: 260px">
            <el-card>
              <!-- 柱状图 -->
              <div ref="echarts2" style="height: 260px"></div>
            </el-card>
            <el-card>
              <!-- 饼状图 -->
              <div ref="echarts3" style="height: 240px"></div>
            </el-card>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import * as echarts from "echarts";
import { getData } from "../../api/ljlApi";

//首先是导入图标们，要用哪个就导入哪个
//例如Search就是那个放大镜的图标
import {
  Search,
  Edit,
  Check,
  Message,
  Star,
  Delete,
  SuccessFilled,
} from "@element-plus/icons";

export default {
  components: {
    Search,
    Edit,
    Check,
    Message,
    Star,
    Delete,
    SuccessFilled,
  },
  data() {
    return {
      // 新建字段
      tableLabel: {
        name: "课程",
        todayBuy: "今日购买",
        monthBuy: "本月购买",
        totalBuy: "总购买",
      },
      // 订单数据
      countData: [
        {
          name: "今日支付订单",
          value: 1234,
          // icon: "SuccessFilled",
          color: "#2ec7c9",
        },
        {
          name: "今日收藏订单",
          value: 210,
          // icon: "SuccessFilled",
          color: "#ffb980",
        },
        {
          name: "今日未支付订单",
          value: 1234,
          // icon: "SuccessFilled",
          color: "#5ab1ef",
        },
        {
          name: "本月支付订单",
          value: 1234,
          // icon: "SuccessFilled",
          color: "#2ec7c9",
        },
        {
          name: "本月收藏订单",
          value: 210,
          // icon: "SuccessFilled",
          color: "#ffb980",
        },
        {
          name: "本月未支付订单",
          value: 1234,
          // icon: "SuccessFilled",
          color: "#5ab1ef",
        },
      ],
      tableData: [],
    };
  },
  mounted() {
    getData().then(({ data }) => {
      const { tableData } = data.data;

      this.tableData = tableData;
      console.log(data.data);
      console.log(this.tableData);

      // 基于准备好的dom，初始化echarts实例
      const echats1 = echarts.init(this.$refs.echats1);
      // 指定图标的配置项和数据
      var echats1Option = {};
      // 处理数据xAxis
      const { orderData, userData, videoData } = data.data;
      const xAxis = Object.keys(orderData.data[0]);
      const xAxisData = {
        data: xAxis,
      };
      echats1Option.xAxis = xAxisData;
      echats1Option.yAxis = {};
      echats1Option.legend = xAxisData;
      echats1Option.series = [];
      xAxis.forEach((key) => {
        echats1Option.series.push({
          name: key,
          data: orderData.data.map((item) => item[key]),
          type: "line",
        });
      });
      console.log(echats1Option);
      // 使用刚指定的配置项和数据显示图表。
      echats1.setOption(echats1Option);

      // 柱状图
      const echarts2 = echarts.init(this.$refs.echarts2);
      const echarts2Option = {
        legend: {
          // 图例文字颜色
          textStyle: {
            color: "#333",
          },
        },
        grid: {
          left: "20%",
        },
        // 提示框
        tooltip: {
          trigger: "axis",
        },
        xAxis: {
          type: "category", // 类目轴
          data: userData.map((item) => item.date),
          axisLine: {
            lineStyle: {
              color: "#17b3a3",
            },
          },
          axisLabel: {
            interval: 0,
            color: "#333",
          },
        },
        yAxis: [
          {
            type: "value",
            axisLine: {
              lineStyle: {
                color: "#17b3a3",
              },
            },
          },
        ],
        color: ["#2ec7c9", "#b6a2de"],
        series: [
          {
            name: "新增用户",
            data: userData.map((item) => item.new),
            type: "bar",
          },
          {
            name: "活跃用户",
            data: userData.map((item) => item.active),
            type: "bar",
          },
        ],
      };
      echarts2.setOption(echarts2Option);

      // 饼状图
      const echarts3 = echarts.init(this.$refs.echarts3);
      const echarts3Option = {
        tooltip: {
          trigger: "item",
        },
        color: [
          "#0f78f4",
          "#dd536b",
          "#9462e5",
          "#a6a6a6",
          "#e1bb22",
          "#39c362",
          "#3ed1cf",
        ],
        series: [
          {
            data: videoData,
            type: "pie",
          },
        ],
      };
      echarts3.setOption(echarts3Option);
    });
  },
};
</script>

<style lang="scss">
.el-breadcrumb {
  margin: 15px 0;
}
.root {
  padding: 20px;
}

.user {
  display: flex;
  align-items: center;
  padding-bottom: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid #ccc;
  img {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    margin-right: 40px;
    border: 2px solid #000;
  }
  .userinfo {
    .name {
      font-size: 32px;
      margin-bottom: 10px;
    }
    .access {
      font-size: 20px;
      color: #999;
    }
  }
}
.login-info {
  p {
    font-size: 14px;
    line-height: 28px;
    color: #999;
    span {
      color: #666;
      margin-left: 60px;
    }
  }
}
.num {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  .icon {
    width: 80px;
    height: 80px;
    font-size: 30px;
    line-height: 80px;
    text-align: center;
    color: #fff;
    background: #2ec7c9;
  }
  .detail {
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin-left: 30px;
    .price {
      font-size: 30px;
      margin-bottom: 10px;
      line-height: 30px;
      height: 30px;
    }
    .dec {
      font-size: 14px;
      color: #999;
      text-align: center;
    }
  }
  .el-card {
    width: 32%;
    height: 80px;
    margin-bottom: 20px;
  }
}
.graph {
  margin-top: 20px;
  display: flex;
  justify-content: space-between;
  .el-card {
    width: 48%;
  }
}
</style>
